from ronglian_sms_sdk import SmsSDK
import json

accId = '2c94811c946f6bfb0196a44ecc2d68cc'
accToken = '369a2c94e49b4c6e8c97fee61e8682e9'
appId = '2c94811c946f6bfb0196a44ecdc268da'


def send_message(phone, code):
    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    mobile = phone
    datas = (code,)
    resp = sdk.sendMessage(tid, mobile, datas)
    # 保证返回 JSON 对象
    if isinstance(resp, str):
        try:
            return json.loads(resp)
        except Exception:
            return {"status": "error", "msg": resp}
    return resp
